class SimpleTableParser extends TableParserInterface {
    async parseHeader(options: { columns: ColumnConfig[]; config?: Partial<HeaderConfig> }): Promise<{
        width: number;
        height: number;
        data: any[];
    }> {
        const { columns, config } = options;
        const headerConfig = {
       ...this.defaultHeaderConfig,
       ...config
        };
        const { font, cell } = headerConfig;
        const { mixWidth: cellMinW, minHeight: cellMinH, fillColor, border } = cell;
        const cellStyle = { fillColor, borderWidth: border.width, borderColor: border.color };
        const cellTextStyle = { fontWeight: font.weight, fontSize: font.fontSize, fontColor: font.fontColor, fontFamily: font.fontFamily };

        const ctx: CanvasRenderingContext2D = document.createElement('canvas').getContext('2d') as CanvasRenderingContext2D;
        if (!ctx) {
            throw new Error('Could not create canvas context for measuring text width.');
        }

        const parseData: any[] = [];
        let totalWidth = 0;
        let maxHeight = 0;

        const processColumns = (columns: ColumnConfig[], level: number = 0): void => {
            columns.forEach((column: ColumnConfig, index: number) => {
                const colItem: any = { type: 'cell', config: {} };
                const { width = null, height = null, label, prop, align = 'center', children = [], wordBreak = 0 } = column;

                let currentWidth: number;
                if (children.length) {
                    const { childWidth, childData } = await this.parseChildCol({
                        children,
                        cellStyle,
                        cellTextStyle,
                        level
                    });
                    colItem.children = childData;
                    currentWidth = childWidth;
                } else {
                    const textWidth = ctx.measureText(label).width;
                    currentWidth = Math.max(textWidth + 10, cellMinW); // 增加一些额外的padding，同时确保不小于最小宽度
                }

                height = height || cellMinH;
                totalWidth += currentWidth;
                maxHeight = Math.max(maxHeight, height * (level + 1));

                // 调用表头解析每列处理后钩子函数，并更新列配置
                const processedColumn = this.onAfterParseHeaderCol? this.onAfterParseHeaderCol(column, index, { totalWidth, maxHeight, data: parseData }) : column;
                const { width: processedWidth, height: processedHeight, label: processedLabel, prop: processedProp, align: processedAlign, children: processedChildren, wordBreak: processedWordBreak } = processedColumn;

                const content = this.splitLabel(processedLabel, processedWordBreak);
                const textAlign = this.getTextAlignFromAlignment(processedAlign);
                cellTextStyle.textAlign = textAlign;
                const location = this.handleCellLocation(index, 0, this.colWidths, 0, level, true);
                colItem.config = { width: processedWidth, height: processedHeight, cellStyle, location, content, cellTextStyle };
                parseData.push(colItem);
            });
        };

        const treeColumns = convertHeaderToTree(columns);
        processColumns(treeColumns);

        return { width: totalWidth, height: maxHeight, data: parseData };
    }

    //...其他方法（如parseChildCol、handleCellLocation等保持原有逻辑或相应调整，这里省略展示）
}

function convertHeaderToTree(columns: ColumnConfig[]): ColumnConfig[] {
    const assignLevelAndParent = (columns: ColumnConfig[], parent: ColumnConfig | null, level: number): void => {
        columns.forEach(column => {
            column.level = level;
            column.parent = parent;
            if (column.children && column.children.length > 0) {
                assignLevelAndParent(column.children, column, level + 1);
            }
        });
    };

    const resultColumns: ColumnConfig[] = JSON.parse(JSON.stringify(columns));
    assignLevelAndParent(resultColumns, null, 0);
    return resultColumns;
}